<template>
    <div class="">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-message"></i>&nbsp;账号密码修改</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <el-form ref="form" label-width="160px">
                <el-form-item label="原密码：">
                    <el-input v-model="oldKey" placeholder="请输入原密码" style="width:300px"></el-input>
                </el-form-item>
                <el-form-item label="新密码：">
                    <el-input v-model="newKey1" placeholder="请输入新密码" style="width:300px"></el-input>
                </el-form-item>
                <el-form-item label="确认新密码：">
                    <el-input v-model="newKey2" placeholder="请再次输入新密码"  style="width:300px"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="confirm">确认修改</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>
<script>
import Cookies from 'js-cookie';
import {postEditAssociation,getAssociationList} from '@/api/school'
export default {
    name:"editPassword",
    data() {
        return {
           id:'',//当前账号id 
           oldKey:'',//账号旧密码
           newKey1:'',//账号新密码
           newKey2:'',//确认的新密码
        }
    },
    //实例创建
    created(){
       //获得 Cookies里的账号信息
       let userInfo = JSON.parse(Cookies.get('sidebarStatus'));
    //    console.log(userInfo);
       this.id = userInfo.admin_id;
    },
    //计算属性
    computed:{

    },
    //方法
    methods: {
        //确认修改
        confirm(){
            var _this =this;
            //先判断两次新密码是否一致
            if(this.newKey1 != this.newKey2){
                this.newKey1 = '';
                this.newKey2 = '';
                this.$message({
                    message: '新密码两次输入不一致',
                    type: 'error'
                });
                return false;
            }else{
           
                //判断不能为空
                if(_this.oldKey == ''){
                _this.$notify.error({
                        title: '请输入账号原密码',
                        duration:2000,
                    });
                    return false;
                }else
                if(_this.newKey1 == ''){
                _this.$notify.error({
                        title: '请输入账号新密码',
                        duration:2000,
                    });
                    return false;
                }
                if(_this.newKey2 == ''){
                _this.$notify.error({
                        title: '请再次输入账号新密码',
                        duration:2000,
                    });
                    return false;
                }
                else{
                    const querystring = require('querystring');
                    const param ={
                        adminId:this.id,
                        oldPwd:this.oldKey,
                        newPwd:this.newKey1,
                    }
                    this.$axios.post('/manage/admin/updatePwd',querystring.stringify(param)).then(response=>{
                        console.log(response);
                        if(response.data.code==200){
                            Cookies.remove('sidebarStatus', { path: '' });
                            _this.$message({
                                message: '恭喜你，修改成功',
                                type: 'success'
                            });
                        setTimeout(function(){
                                _this.$router.push('/login');
                        },3100)
                        
                        }else{
                            _this.$notify.error({
                                title: '修改失败',
                                duration:2000,
                                message: '失败原因：'+response.data.msg
                            });
                        }
                        
                    }).catch(error=>{
                        console.log(error); 
                    });
                }
             }    
        },
    }
}
</script>
<style lang="stylus" scoped>
   
</style>


